home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / admin / dig-2.0 / dig-2 / dig.2.0 / herror.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-04  |  1.2 KB  |  55 lines

  1. /*
  2.  * Copyright (c) 1987 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. /*
  8. ** Distributed with 'dig' version 2.0 from University of Southern
  9. ** California Information Sciences Institute (USC-ISI) 9/1/90.
  10. */
  11.  
  12. #if defined(LIBC_SCCS) && !defined(lint)
  13. static char sccsid[] = "@(#)herror.c    6.1 (Berkeley) 12/4/87";
  14. #endif LIBC_SCCS and not lint
  15.  
  16. #include <sys/types.h>
  17. #include <sys/uio.h>
  18.  
  19. char    *h_errlist[] = {
  20.     "Error 0",
  21.     "Unknown host",                /* 1 HOST_NOT_FOUND */
  22.     "Host name lookup failure",        /* 2 TRY_AGAIN */
  23.     "Unknown server error",            /* 3 NO_RECOVERY */
  24.     "No address associated with name",    /* 4 NO_ADDRESS */
  25. };
  26. int    h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) };
  27.  
  28. extern int    h_errno;
  29.  
  30. /*
  31.  * herror --
  32.  *    print the error indicated by the h_errno value.
  33.  */
  34. herror(s)
  35.     char *s;
  36. {
  37.     struct iovec iov[4];
  38.     register struct iovec *v = iov;
  39.  
  40.     if (s && *s) {
  41.         v->iov_base = s;
  42.         v->iov_len = strlen(s);
  43.         v++;
  44.         v->iov_base = ": ";
  45.         v->iov_len = 2;
  46.         v++;
  47.     }
  48.     v->iov_base = h_errno < h_nerr ? h_errlist[h_errno] : "Unknown error";
  49.     v->iov_len = strlen(v->iov_base);
  50.     v++;
  51.     v->iov_base = "\n";
  52.     v->iov_len = 1;
  53. (void)    writev(2, iov, (v - iov) + 1);
  54. }
  55.